<?php
class classPaimentType extends phpajax{
    function input(){
        aread('cbDeliveryType_Selected');
    }
    function loading(){}

    function main(){
        if(
          trim($this->cbDeliveryType_Selected)!='' and 
          $this->cbDeliveryType_Selected!=0 and
          is_numeric($this->cbDeliveryType_Selected)
        ){
          aprint('order_payment_container', $this->getPaymentList($this->cbDeliveryType_Selected));
        }
    }
    
    
    public function getPaymentList($iDeliveryType){        
        return $this->getComboBoxWithPayment($this->getDataFromDB($iDeliveryType));
    }
    
    private function getDataFromDB($iDeliveryType){
        $result = '';
        $sql_result = mysql_query('
          SELECT 
            pt_id,
            pt_name
          FROM 
            delivery_payment,
            payment_types
          WHERE
            dt_id = '.$iDeliveryType.' AND
            pt_id = payment_types.id
        ');
        while ($sql_obj = mysql_fetch_object($sql_result))
          $result[$sql_obj->pt_id] .= $sql_obj->pt_name;
        return $result;
    }
    
    private function getComboBoxWithPayment($asPaymentList){
        $result = '
          '._i18n_order_SELECT_TYPE_OF_PAYMENT_.':
          <select name="cbPaymentType" id="cbPaymentType">
        ';
        $result .= '<option value ="0">'._i18n_order_SELECT_.'</option>';
        foreach ($asPaymentList as $key => $value) { 
          $result .= '<option value ="'.$key.'">'.$value.'</option>';
        }
        $result .= '</select>';
        
        return $result;
    }
}
?>
